package 剑指Offer._2130;

import general_class.ListNode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/7/26 9:21
 * 反转链表
 * 算法：链表  递归  栈  迭代
 */
public class _24 {

    public ListNode reverseList(ListNode head) {
        Deque<Integer> stack = new LinkedList<>();
        ListNode cur = head;
        while (null != cur) {
            stack.push(cur.val);
            cur = cur.next;
        }
        cur = head;
        while (!stack.isEmpty()) {
            cur.val = stack.pop();
            cur = cur.next;
        }
        return head;
    }

}
